<%@ page import="java.sql.ResultSet" %>
<%@ page import="org.omg.CORBA.NO_IMPLEMENT" %>

<%@ include file="connect.jsp" %>
<%--
  Created by IntelliJ IDEA.
  User: Mery
  Date: 10/25/12
  Time: 11:03 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    if (session.getAttribute("namaUser") == null) {

        response.sendRedirect("login.jsp?respon=You have to login first!");
    }

%>
<html>

<head>
    <title>Business English</title>
    <link href="style.css" rel="stylesheet"/>
    <link href="menu.css" rel="stylesheet"/>
    <script type="text/javascript" language="javascript">
        function confirmAction() {
            var confirmed = confirm("Are you sure to delete this category?");
            return confirmed;
        }
    </script>
    <script src="jquery.js" type="text/javascript"></script>
    <script src="facebox.js" type="text/javascript"></script>
    <script type="text/javascript">
        jQuery(document).ready(function ($) {
            $('a[rel*=facebox]').facebox({
                loadingImage:'images/loading.gif',
                closeImage:'images/closelabel.png'
            })
        })
    </script>
</head>

<body>
<table id="bg" cellspacing="0">

    <tr id="header">
        <td class="link">
            <%@ include file="header.jsp" %>
        </td>
    </tr>
    <tr id="menu">
        <td>
            <%@ include file="menu.jsp" %>
        </td>
    </tr>
    <tr id="hr">
        <td>
            <hr width="100%" size="8" noshade="noshade">
        </td>
    </tr>


    <tr id="content">

        <td class="link" valign="top" style="padding-left: 20px">

            <table>
                <tr id="title">

                    <td>Category</td>
                </tr>
                <tr>
                    <td>
                        <div class="btn-fld">
                            <a id="categories" rel="facebox" href="addNewCategories.jsp">
                                <button type="button">Add New Category</button>
                            </a>
                        </div>
                    </td>
                </tr>
                <table>
                    <tr id="warning">
                        <td>
                            <%
                                String respon = request.getParameter("respon");

                                if (respon != null) {

                                    out.print(respon + " ");
                                }
                            %>


                        </td>

                    </tr>
                </table>
                <table id="bor1" border="2" width="400px">
                    <tr style="text-align: center; font-weight: 600">
                        <td width="10px">No.</td>
                        <td width="200px">Category Name</td>
                        <td>Action</td>
                    </tr>

                    <%

                        int i = 0;

                        ResultSet rs = stat.executeQuery("select * from categories");

                        while (rs.next()) {
                            i = i + 1; %>
                    <tr>
                        <td style="text-align: center"><%=i%>
                        </td>
                        <td style="padding-left: 10px"><%out.print(rs.getString("categoryName"));%></td>
                        <td align="center">
                            <a href="EditCatName.jsp?id=<%out.print(rs.getString("categoryID"));%>" rel="facebox"> <img
                                    height="25px" src="edit.png" title="Edit Category Name"></a>&nbsp;&nbsp;
                            <a href="doDeleteCat.jsp?id=<%out.print(rs.getString("categoryID"));%>&nama=<%out.print(rs.getString("categoryName"));%>"
                               onclick="return confirmAction()"><img height="25px" src="Delete.png"
                                                                     title="Delete Category"></a></td>
                    </tr>

                    <% }
                        conn.close();
                    %>


                </table>

            </table>

        </td>
    </tr>

</table>
</body>
</html>